<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>



<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.08">
<LINK rel="stylesheet" type="text/css" href="umsroot.css">
<TITLE>
Debugging Parts of Programs
</TITLE>
</HEAD>
<BODY >
<A HREF="umsroot078.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="umsroot074.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="umsroot080.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>

<H2 CLASS="section"><A NAME="htoc190">14.5</A>&nbsp;&nbsp;Debugging Parts of Programs</H2><UL>
<LI><A HREF="umsroot079.html#toc113">Mixing debuggable and non-debuggable code</A>
</UL>

<A NAME="toc113"></A>
<H3 CLASS="subsection"><A NAME="htoc191">14.5.1</A>&nbsp;&nbsp;Mixing debuggable and non-debuggable code</H3>
The debugger can trace only procedures which have been compiled in
debug mode. The compiler debug mode is by default switched on and it
can be changed globally by setting the flag <I>debug_compile</I> with the
<A HREF="../bips/kernel/env/set_flag-2.html"><B>set_flag/2</B></A><A NAME="@default791"></A>
predicate or using
<A HREF="../bips/kernel/obsolete/dbgcomp-0.html"><B>dbgcomp/0</B></A><A NAME="@default792"></A> or
<A HREF="../bips/kernel/obsolete/nodbgcomp-0.html"><B>nodbgcomp/0</B></A><A NAME="@default793"></A>.
The global compiler debug mode can be overruled on a file-by-file basis
using one of the compiler pragmas
<BLOCKQUOTE CLASS="quote"><PRE CLASS="verbatim">
:- pragma(nodebug).
:- pragma(debug).
</PRE></BLOCKQUOTE>
Once a program (or a part of it) has been
debugged, it can be compiled in <I>nodbgcomp</I> mode so that all
optimisations are done by the compiler. The advantages of
non-debugged procedures are
<UL CLASS="itemize"><LI CLASS="li-itemize">
They run slightly faster than the debugged procedures
when the debugger is switched off. When the debugger is switched on,
the non-debugged procedures run considerably faster than the debugged
ones and so the user can selectively influence the speed of the code
which is being traced as well as its space consumption.<BR>
<BR>
<LI CLASS="li-itemize">Their code is shorter than that of the debugged procedures.
</UL>
Although only procedures compiled in the <I>dbgcomp</I> mode can be
traced, it is possible to mix the execution of procedures in both
modes. Then, calls of <I>nodbgcomp</I> procedures from <I>dbgcomp</I> ones are
traced, however further execution within <I>nodbgcomp</I> procedures,
i.e. the execution of their subgoals, no matter in which mode, is not
traced. In particular, when a <I>nodbgcomp</I> procedure calls a <I>dbgcomp</I>
one, the latter is normally not traced.
There are two important exceptions from this rule:
<UL CLASS="itemize"><LI CLASS="li-itemize">
<A NAME="@default794"></A>
When a debuggable procedure has delayed and its DELAY port has
been traced, then its RESUME port is also traced, even when it is woken
inside non-debuggable code.
<A NAME="@default795"></A>
<A NAME="@default796"></A>
<A NAME="@default797"></A>
<LI CLASS="li-itemize">When non-debuggable code <I>meta-calls</I> a debuggable procedure
(i.e. via <A HREF="../bips/kernel/control/call-1.html"><B>call/1</B></A><A NAME="@default798"></A>),
then this procedure can be traced. This is a useful feature for the
implementation of meta- predicates like
<A HREF="../bips/kernel/allsols/setof-3.html"><B>setof/3</B></A><A NAME="@default799"></A>, because it
allows to hide the details of the setof-implementation, while allowing
to trace the argument goal.
</UL>
Setting a procedure to skipped (with
<A HREF="../bips/kernel/compiler/set_flag-3.html"><B>set_flag/3</B></A><A NAME="@default800"></A> or
<A HREF="../bips/kernel/debug/skipped-1.html"><B>skipped/1</B></A><A NAME="@default801"></A>
)
is another way
to speed up the execution of procedures that do not need to be
debugged. The debugger will ignore everything that is called inside
the skipped procedure like for a procedure compiled in <I>nodbgcomp</I>
mode. However, the debugger will keep track of the execution of a
procedure skipped with the command <B>s</B> of the debugger so that it
will be possible to 'creep' in it on later backtracking or switch the
debugger to <I>creep</I> mode while the skip is running (e.g. by
interrupting a looping predicate with C and switching to <I>creep</I> mode).<BR>
<BR>
The two predicates
<A HREF="../bips/kernel/debug/trace-1.html"><B>trace/1</B></A><A NAME="@default802"></A> and
<A HREF="../bips/kernel/debug/debug-1.html"><B>debug/1</B></A><A NAME="@default803"></A> can be used to
switch on the debugger in the middle of a program. They execute their
argument in <I>creep</I> or <I>leap</I> mode respectively. This is
particularly useful when debugging large programs that take too much
time (or need a lot of memory) to run completely with the debugger.
<BLOCKQUOTE CLASS="quote"><PRE CLASS="verbatim">
[eclipse 1]: debugging.
Debugger is switched off

yes.
[eclipse 2]: big_goal1, trace(buggy_goal), big_goal2.
Start debugging - creep mode
  (1) 0  CALL   buggy_goal %&gt; c creep
  (1) 0  EXIT   buggy_goal %&gt; c creep
Stop debugging.

yes.
</PRE></BLOCKQUOTE>
It is also possible to enable the debugger in the middle of execution
without changing the code. To do so, use
<A HREF="../bips/kernel/compiler/set_flag-3.html"><B>set_flag/3</B></A><A NAME="@default804"></A>
<A NAME="@default805"></A>
to set the <B>start_tracing</B> flag of the predicate of interest.
Tracing will then start (in leap mode) at every call of this
predicate<SUP><A NAME="text23" HREF="umsroot074.html#note23">1</A></SUP>. To see the starting predicate itself,
set a spy point in addition to the <B>start_tracing</B> flag:
<BLOCKQUOTE CLASS="quote"><PRE CLASS="verbatim">
[eclipse 1]: debugging.
Debugger is switched off

yes.
[eclipse 2]: set_flag(buggy_goal/0, start_tracing, on),
             set_flag(buggy_goal/0, spy, on).

yes.
[eclipse 3]: big_goal1, buggy_goal, big_goal2.
 +(0) 0 CALL  buggy_goal   %&gt; creep
 +(0) 0 EXIT  buggy_goal   %&gt; creep

yes.
</PRE></BLOCKQUOTE>
In tkeclipse, the debugger can also be started in this way. The tracer tool
will popup at the appropriate predicate if it has not been invoked
already. The <B>start_tracing</B> flag can also be set with the predicate
browser tool.<BR>
<BR>
<HR>
<A HREF="umsroot078.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="umsroot074.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="umsroot080.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>
